//package com.inspur.edp.bef.dtgenerator.core.mgrImpl;
//
//import com.inspur.edp.bef.bizentity.GspBizEntityObject;
//import com.inspur.edp.bef.bizentity.GspBusinessEntity;
//import com.inspur.edp.bef.dtgenerator.core.BefCoreGenCtx;
//import com.inspur.edp.caf.generator.baseInfo.TypeInfo;
//import com.inspur.edp.caf.generator.property.ClassPropertyGenerator;
//import com.inspur.edp.cef.designtime.api.collection.BaseList;
//import com.inspur.edp.cef.entity.UQConstraintConfig;
//import com.inspur.edp.das.commonmodel.IGspCommonElement;
//import com.inspur.edp.das.commonmodel.collection.GspUniqueConstraintCollection;
//import com.inspur.edp.das.commonmodel.entity.object.GspUniqueConstraint;
//import org.eclipse.jdt.core.dom.*;
//
//import java.util.ArrayList;
//import java.util.Arrays;
//import java.util.HashMap;
//import java.util.Map;
//
//public class UQConstraintInfoProGenerator extends ClassPropertyGenerator {
//  private BefCoreGenCtx coreGenCtx;
//
//  public UQConstraintInfoProGenerator(BefCoreGenCtx coreGenCtx) {
//    this.coreGenCtx = coreGenCtx;
//  }
//
//  @Override
//  protected ArrayList<Modifier.ModifierKeyword> getGetterAccessModifier() {
//    return new ArrayList<Modifier.ModifierKeyword>(
//        Arrays.asList(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
//  }
//
//  @Override
//  protected ArrayList<Modifier.ModifierKeyword> getSetterAccessModifier() {
//    return null;
//  }
//
//  @Override
//  protected String getPropertyName() {
//    return "UQConstraintInfo";
//  }
//
//  @Override
//  protected TypeInfo getPropertyType() {
//    coreGenCtx.addImport(HashMap.class.getName());
//    TypeInfo typeInfo = new TypeInfo(HashMap.class);
//    typeInfo.setIsParameterizedType(true);
//
//    typeInfo.getArguments().add(new TypeInfo(String.class));
//
//    TypeInfo argType2 = new TypeInfo(ArrayList.class );
//    argType2.setIsParameterizedType(true);
//
//    TypeInfo argTypeUQ = new TypeInfo(UQConstraintConfig.class);
//    argType2.getArguments().add(argTypeUQ);
//    typeInfo.getArguments().add(argType2);
//    return typeInfo;
//  }
//
//  @Override
//  protected String getFieldName() {
//    return null;
//  }
//
//  @Override
//  protected boolean hasSetMethod() {
//    return false;
//  }
//
//  @Override
//  protected boolean hasGetMethod() {
//    return true;
//  }
//
//  private HashMap<String, ArrayList<UQConstraintConfig>> getContent() {
//    GspBusinessEntity be = coreGenCtx.getBE();
//
//    ArrayList<GspBizEntityObject> nodes = be.getAllNodes();
//    HashMap<String, ArrayList<UQConstraintConfig>> dic =
//        new HashMap<String, ArrayList<UQConstraintConfig>>();
//
//    for (GspBizEntityObject node : nodes) {
//      ArrayList<UQConstraintConfig> result = new ArrayList<UQConstraintConfig>();
//
//      GspUniqueConstraintCollection constraints = node.getContainConstraints();
//
//      for (GspUniqueConstraint item : constraints) {
//        UQConstraintConfig config = new UQConstraintConfig();
//        config.setConstraintFields(new ArrayList<String>());
//        config.setUQConstraintCode(item.getCode());
//        GspUniqueConstraint constraint = item;
//        config.setMessage(
//            (constraint.getConstraintMessage() != null) ? constraint.getConstraintMessage() : "");
//
//        BaseList<String> elements = constraint.getElementList();
//
//        for (String elementId : elements) {
//          IGspCommonElement ele = node.findElement(elementId);
//          if(ele==null){
//            throw new RuntimeException("当前"+be.getCode()+",节点"+node.getCode()+"上的唯一性约束字段不存在，字段ID为："+elementId);
//          }
//          config.getConstraintFields().add(ele.getLabelID());
//        }
//
//        result.add(config);
//      }
//      if (node.getIsRootNode()) {
//        dic.put(node.getCode(), result);
//      } else {
//        dic.put(node.getCode(), result);
//      }
//    }
//    return dic;
//  }
//
//  @Override
//  protected Block buildGetMethodBody() {
//    coreGenCtx.addImport(UQConstraintConfig.class.getName());
//
//    Block block = ast.newBlock();
//    addNewHashMapExpression(block);
//    addSetNodesExpressions(block);
//    addReturnExpression(block);
//    return block;
//  }
//
//  private void addNewHashMapExpression(Block block) {
//    VariableDeclarationFragment variableDeclarationFragment=ast.newVariableDeclarationFragment();
//    variableDeclarationFragment.setName(ast.newSimpleName("dict"));
//    setHashSetVariableInitializer(variableDeclarationFragment);
//    VariableDeclarationStatement variableDeclarationStatement=ast.newVariableDeclarationStatement(variableDeclarationFragment);
//    setHashSetType(variableDeclarationStatement);
//    block.statements().add(variableDeclarationStatement);
//
//  }
//
//
//  private void setHashSetVariableInitializer(VariableDeclarationFragment variableDeclarationFragment) {
//    ClassInstanceCreation classInstanceCreation=ast.newClassInstanceCreation();
//    ParameterizedType type =ast.newParameterizedType(ast.newSimpleType(ast.newName(HashMap.class.getTypeName())));
//    classInstanceCreation.setType(type);
//    variableDeclarationFragment.setInitializer(classInstanceCreation);
//  }
//
//  private void setHashSetType(VariableDeclarationStatement variableDeclarationStatement) {
//    ParameterizedType type =ast.newParameterizedType(ast.newSimpleType(ast.newName(HashMap.class.getTypeName())));
//    type.typeArguments().add(ast.newSimpleType(ast.newSimpleName("String")));
//
//    ParameterizedType listType =ast.newParameterizedType(ast.newSimpleType(ast.newName(ArrayList.class.getTypeName())));
//    listType.typeArguments().add(ast.newSimpleType(ast.newName(UQConstraintConfig.class.getTypeName())));
//
//    type.typeArguments().add(listType);
//    variableDeclarationStatement.setType(type);
//  }
//
//  private void addSetNodesExpressions(Block block) {
//    HashMap<String, ArrayList<UQConstraintConfig>> contents =getContent();
//    if(contents ==null||contents.size()==0)
//      return;
//    for (Map.Entry<String,ArrayList<UQConstraintConfig>> content:contents.entrySet())
//    {
//      addSetNodeExpression(block,content);
//    }
//  }
//
//  //    ArrayList<UQConstraintConfig> list =new ArrayList<>();
////    for (UQConstraintConfig config1:content.getValue())
////    {
////      UQConstraintConfig config=new UQConstraintConfig();
////      ArrayList<String> fields =new ArrayList<>();
////      fields.add("ff1");
////      config.setConstraintFields(fields);
////      config.setMessage("ddd");
////      list.add(config);
////    }
////    dic.put("sdaf",list);
//  private void addSetNodeExpression(Block block, Map.Entry<String, ArrayList<UQConstraintConfig>> content) {
//    Block block1=ast.newBlock();
//    addSetNodeNewConfigList(block1);
//    for (UQConstraintConfig config:content.getValue())
//      addSetConfigExpression(config,block1);
//    setAddListToDict(content,block1);
//    block.statements().add(block1);
//  }
//
//    private void setAddListToDict(Map.Entry<String, ArrayList<UQConstraintConfig>> content, Block block1) {
//      MethodInvocation methodInvocation=ast.newMethodInvocation();
//      methodInvocation.setName(ast.newSimpleName("put"));
//      methodInvocation.setExpression(ast.newSimpleName("dict"));
//      StringLiteral stringLiteral=ast.newStringLiteral();
//      stringLiteral.setLiteralValue(content.getKey());
//      methodInvocation.arguments().add(stringLiteral);
//      methodInvocation.arguments().add(ast.newSimpleName("list"));
//      block1.statements().add(ast.newExpressionStatement(methodInvocation));
//    }
//
//    private void addSetConfigExpression(UQConstraintConfig config, Block block1) {
//    Block block2= ast.newBlock();
//    addNewConfig(block2,config);
//    addSetNodeConfigFields(block2,config);
//    addSetNodeConfigCode(block2, config);
//    addSetNodeConfigMessage(block2,config);
//    addAddConfigToList(block2);
//    block1.statements().add(block2);
//  }
//
//  private void addNewConfig(Block block1, UQConstraintConfig config) {
//    VariableDeclarationFragment variableDeclarationFragment=ast.newVariableDeclarationFragment();
//    variableDeclarationFragment.setName(ast.newSimpleName("config"));
//    ClassInstanceCreation classInstanceCreation=ast.newClassInstanceCreation();
//    classInstanceCreation.setType(ast.newSimpleType(ast.newName(UQConstraintConfig.class.getTypeName())));
//    variableDeclarationFragment.setInitializer(classInstanceCreation);
//    VariableDeclarationStatement variableDeclarationStatement=ast.newVariableDeclarationStatement(variableDeclarationFragment);
//    variableDeclarationStatement.setType(ast.newSimpleType(ast.newName(UQConstraintConfig.class.getTypeName())));
//    block1.statements().add(variableDeclarationStatement);
//  }
//
//  private void addAddConfigToList(Block block1) {
////list.add(config);
//    MethodInvocation methodInvocation=ast.newMethodInvocation();
//    methodInvocation.setName(ast.newSimpleName("add"));
//    methodInvocation.setExpression(ast.newSimpleName("list"));
//    methodInvocation.arguments().add(ast.newSimpleName("config"));
//    block1.statements().add(ast.newExpressionStatement(methodInvocation));
//  }
//
//  private void addSetNodeNewConfigList(Block block1) {
//    VariableDeclarationFragment variableDeclarationFragment=ast.newVariableDeclarationFragment();
//    variableDeclarationFragment.setName(ast.newSimpleName("list"));
//    ClassInstanceCreation classInstanceCreation=ast.newClassInstanceCreation();
//    classInstanceCreation.setType(ast.newParameterizedType(ast.newSimpleType(ast.newName(ArrayList.class.getTypeName()))));
//    variableDeclarationFragment.setInitializer(classInstanceCreation);
//
//    VariableDeclarationStatement variableDeclarationStatement=ast.newVariableDeclarationStatement(variableDeclarationFragment);
//    ParameterizedType parameterizedType=ast.newParameterizedType(ast.newSimpleType(ast.newName(ArrayList.class.getTypeName())));
//    parameterizedType.typeArguments().add(ast.newSimpleType(ast.newName(UQConstraintConfig.class.getTypeName())));
//    variableDeclarationStatement.setType(parameterizedType);
//    block1.statements().add(variableDeclarationStatement);
//  }
//
//  private void addSetNodeConfigFields(Block block1, UQConstraintConfig config) {
//    addNewFieldList(block1);
//    setFieldItems(block1,config);
//    addSetFields(block1,config);
//  }
//
//  private void setFieldItems(Block block1, UQConstraintConfig config) {
//    for(String field:config.getConstraintFields())
//    {
//      MethodInvocation methodInvocation=ast.newMethodInvocation();
//      methodInvocation.setName(ast.newSimpleName("add"));
//      methodInvocation.setExpression(ast.newSimpleName("fields"));
//      StringLiteral stringLiteral=ast.newStringLiteral();
//      stringLiteral.setLiteralValue(field);
//      methodInvocation.arguments().add(stringLiteral);
//      block1.statements().add(ast.newExpressionStatement(methodInvocation));
//    }
//  }
//
//  private void addSetFields(Block block1, UQConstraintConfig config) {
////    config.setConstraintFields(fields);
//    MethodInvocation methodInvocation=ast.newMethodInvocation();
//    methodInvocation.setName(ast.newSimpleName("setConstraintFields"));
//    methodInvocation.setExpression(ast.newSimpleName("config"));
//    methodInvocation.arguments().add(ast.newSimpleName("fields"));
//    block1.statements().add(ast.newExpressionStatement(methodInvocation));
//  }
//
//  private void addNewFieldList(Block block1) {
//    VariableDeclarationFragment variableDeclarationFragment=ast.newVariableDeclarationFragment();
//    variableDeclarationFragment.setName(ast.newSimpleName("fields"));
//    ClassInstanceCreation classInstanceCreation=ast.newClassInstanceCreation();
//    classInstanceCreation.setType(ast.newParameterizedType(ast.newSimpleType(ast.newName(ArrayList.class.getTypeName()))));
//    variableDeclarationFragment.setInitializer(classInstanceCreation);
//    VariableDeclarationStatement variableDeclarationStatement=ast.newVariableDeclarationStatement(variableDeclarationFragment);
//    ParameterizedType parameterizedType=ast.newParameterizedType(ast.newSimpleType(ast.newName(ArrayList.class.getTypeName())));
//    parameterizedType.typeArguments().add(ast.newSimpleType(ast.newSimpleName("String")));
//    variableDeclarationStatement.setType(parameterizedType);
//    block1.statements().add(variableDeclarationStatement);
//  }
//
//  private void addSetNodeConfigCode(Block block1, UQConstraintConfig config) {
//    MethodInvocation methodInvocation=ast.newMethodInvocation();
//    methodInvocation.setName(ast.newSimpleName("setUQConstraintCode"));
//    methodInvocation.setExpression(ast.newSimpleName("config"));
//    StringLiteral stringLiteral=ast.newStringLiteral();
//    stringLiteral.setLiteralValue(config.getUQConstraintCode());
//    methodInvocation.arguments().add(stringLiteral);
//    block1.statements().add(ast.newExpressionStatement(methodInvocation));
//  }
//
//  private void addSetNodeConfigMessage(Block block1, UQConstraintConfig config) {
////config.setMessage("");
//    MethodInvocation methodInvocation=ast.newMethodInvocation();
//    methodInvocation.setName(ast.newSimpleName("setMessage"));
//    methodInvocation.setExpression(ast.newSimpleName("config"));
//    StringLiteral stringLiteral=ast.newStringLiteral();
//    stringLiteral.setLiteralValue(config.getMessage());
//    methodInvocation.arguments().add(stringLiteral);
//    block1.statements().add(ast.newExpressionStatement(methodInvocation));
//  }
//
//  private void addReturnExpression(Block block) {
//    ReturnStatement returnStatement=ast.newReturnStatement();
//    returnStatement.setExpression(ast.newSimpleName("dict"));
//    block.statements().add(returnStatement);
//  }
//
//  public void Test()
//  {
//    HashMap<String,ArrayList<UQConstraintConfig>> dict =new HashMap<>();
//    ArrayList<UQConstraintConfig> list =new ArrayList<>();
//  }
//  @Override
//protected boolean isGetterOverride()
//{
// return false;
//}
//}
